package edu.ynu.se.xiecheng.achitectureclass.project.po.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

@Entity
@Getter
@Setter
@Table(name = "device")
public class Device extends LogicEntity {

    @Column(name = "device_id", nullable = false, unique = true)
    private String  deviceId; // 设备唯一标识

    @Column(name = "name", nullable = false)
    private String name; // 设备名称

    @JsonBackReference
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "box_id", nullable = false)
    private Greenhouse greenhouse; // 所属大棚

    @JsonManagedReference
    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<SoilPHData> phData; // PH 数据

    @JsonManagedReference
    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<SoilNitrogenData> nitrogenData; // 氮气数据

    @JsonManagedReference
    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<SoilPhosphorusData> soilPhosphorusData; // 土壤磷数据

    @JsonManagedReference
    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<SoilPotassiumData> soilPotassiumData;//土壤钾数据

    @JsonManagedReference
    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<SoilTemperatureData> soilTemperatureData;//土壤温度数据

    @JsonManagedReference
    @OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<AirTemperatureData> airTemperatureData;//空气温度数据

}

